const fs = require("fs");

const YAML = require("yaml");

/**
 * 
 * @returns { { users: {username: string, password: string, privilege: string}[], groups: {groupname: string, users: string[], privilege: string}[]} }
 */
 function readAccountCfg() {
    try {
        var accountDataStr = fs.readFileSync('./cfg/account.yml', {
            encoding: "utf-8"
        });
        var accountData = YAML.parse(accountDataStr);
        return accountData;
    } catch (error) {
        console.log("Read account error", error);
    }
}

function readBootstrapConfig() {
    try {
        var raw = fs.readFileSync('./cfg/bootstrap.yml', {
            encoding: "utf-8"
        });
        var data = YAML.parse(raw);
        return data;
    } catch (error) {
        console.log("Read bootstrap error", error);
    }
}


module.exports = {
    readAccountCfg,
    readBootstrapConfig,
};